package small.hero.sexual.life.tips.zl;


import small.hero.pageview.ScrollablePageContainer;
import small.hero.pageview.ScrollablePageContainer.PageScrollListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class ShowContent extends Activity {
	private String[] mStrings;
	private ScrollablePageContainer linearLayoutText;


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getModel();
		test();
	}

	 private void test() {
	        final FrameLayout layout = new FrameLayout(this);
	        //PS: 另外个例子没有做，可以使用AnimableScrollablePageContainer来实现2类翻页效果的同时，
	        // 支持系统的各种Animation的切换。那个代码写的很简单，可以看着用。
	        final ScrollablePageContainer container = new ScrollablePageContainer(this);
	        //理论上说，这个view1, view2可以是任何的控件。
	        final ContentView view1 = new ContentView(this);
	        final ContentView view2 = new ContentView(this);
	        view1.setClickable(true);
	        view2.setClickable(true);
	        //用作容器的2个控件需要有一个背景，如果是透明的话，翻页时将可以看到下一页的内容。
	        //不好描述...可以尝试注释掉下面2行代码看看效果.
	        view1.setBackgroundColor(Color.WHITE);
	        view2.setBackgroundColor(Color.WHITE);
	        container.addView(view1);
	        container.addView(view2);
	        container.setFrontView(view1);
	        container.setBackgroundView(view2);
	        view1.bind(mStrings[0]);
	        //note: pageTurningEnable和horizontalScroll & verticalScroll是冲突的
	        container.setPageTurningEnabled(true);
	        //如果只是要翻页效果，下面这2个属性的设置是没用的。
	        //这里只是为了演示效果，点击option 按钮可以切换翻页模式。
//	        container.setHorizontalScrollable(true);
	        container.setVerticalScrollable(true);
	        //note: listener用于数据绑定。
	        container.setPageScrollListener(new PageScrollListener() {

	            @Override
	            public boolean onScrollStarted(int scrollOrientation, View scrollToView,
	                    int scrollToPageIndex) {
	            	final ContentView view = (ContentView) scrollToView;
	            	  Log.d(TAG,  " [onScrollStarted] onScrollStarted =" + scrollOrientation);
	            	if (scrollOrientation ==ScrollablePageContainer.SCROLL_ORIENTATION_LEFT_TO_RIGHT ) {
	            		if (mIndex>0) {
	            			mIndex --;
	            			view.bind(mStrings[mIndex]);
						}else {
							Toast.makeText(ShowContent.this, "This is the first page.", Toast.LENGTH_SHORT).show();
							view.bind(mStrings[mIndex]);
						}
					}else if (scrollOrientation == ScrollablePageContainer.SCROLL_ORIENTATION_RIGHT_TO_LEFT) {
						if (mIndex<mStrings.length-1) {
	            			mIndex ++;
	            			view.bind(mStrings[mIndex]);
						}else {
							Toast.makeText(ShowContent.this, "This is the last page.", Toast.LENGTH_SHORT).show();
							view.bind(mStrings[mIndex]);
						}
					}
	                return true;
	            }

	            @Override
	            public void onScrollReseted(int scrollOrientation) {
	            	Log.d(TAG,  " [onScrollReseted] onScrollStarted =" + scrollOrientation);
	            }

	            @Override
	            public void onScrollFinished(int scrollOrientation, int scrollToPageIndex) {
	            	Log.d(TAG,  " [onScrollFinished] scrollOrientation =" + scrollOrientation);
	            }
	        });
			final AdView adView = new AdView(this, AdSize.BANNER, "a14e3bcb363a67c");
			adView.loadAd(new AdRequest());
			final LayoutParams params1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params1.gravity= Gravity.BOTTOM;
	        layout.addView(container);
	        layout.addView(adView,params1);
	        setContentView(layout);
	    }
	 int mIndex = 0;
	
	
	
	
	
	

	private void getModel() {
		final int gameModle = getIntent().getIntExtra("Model", -1);
		switch (gameModle) {
		case 0:
			mStrings = getResources().getStringArray(R.array.ColourandSex);
			break;
		case 1:
			mStrings = getResources().getStringArray(R.array.StarSignandSex);
			break;
		case 2:
			mStrings = getResources().getStringArray(R.array.WhatMenWant);
			break;
		case 3:
			mStrings = getResources().getStringArray(
					R.array.Whatmenshoulddoaftersex);
			break;
		case 4:
			mStrings = getResources().getStringArray(
					R.array.Howtogetinmoodin5minute);
			break;
		case 5:
			mStrings = getResources().getStringArray(R.array.WhatYourSexStyle);
			break;
		case 6:
			mStrings = getResources().getStringArray(
					R.array.GetTheBestOutofYourSexPositions);
			break;
		case 7:
			mStrings = getResources()
					.getStringArray(R.array.Changeyoursexstyle);
			break;
		case 8:
			mStrings = getResources().getStringArray(R.array.TakeHimBySurprise);
			break;
		case 9:
			mStrings = getResources().getStringArray(
					R.array.SpiceupyourlovelifewithAphrodisiacs);
			break;
		case 10:
			mStrings = getResources().getStringArray(
					R.array.EssentialsofForeplay);
			break;
		case 11:
			mStrings = getResources().getStringArray(R.array.TheOralEcstasy);
			break;
		case 12:
			mStrings = getResources().getStringArray(R.array.PleasingYourself);
			break;
		case 13:
			mStrings = getResources().getStringArray(
					R.array.OralEcstasyTheGspot);
			break;
		case 14:
			mStrings = getResources().getStringArray(R.array.TouchandFeel);
			break;
		case 15:
			mStrings = getResources().getStringArray(
					R.array.Learntotouchyourwoman);
			break;

		case 16:
			mStrings = getResources().getStringArray(R.array.SensuousSexGames);
			break;
		case 17:
			mStrings = getResources().getStringArray(R.array.Placestomakelove);
			break;
		case 18:
			mStrings = getResources().getStringArray(R.array.GetintheGroove);
			break;
		case 19:
			mStrings = getResources().getStringArray(
					R.array.Tipstoturnhimontonight);
			break;
		case 20:
			mStrings = getResources()
					.getStringArray(R.array.HowToSeduceYourMan);
			break;
		case 21:
			mStrings = getResources().getStringArray(
					R.array.Howtomakeyourmanhappy);
			break;

		case 22:
			mStrings = getResources().getStringArray(
					R.array.SexualPositionsWomenEnjoy);
			break;
		case 23:
			mStrings = getResources().getStringArray(R.array.SensuousBath);
			break;
		case 24:
			mStrings = getResources().getStringArray(
					R.array.MysteriesofFragrance);
			break;
		}
	}
	private static final String TAG = ShowContent.class.getSimpleName();
	private class ContentView extends FrameLayout {

        private final TextView mTxt;
        private final ScrollView mScrollView;
        public ContentView(Context context) {
            super(context);
            mTxt = new TextView(context);
            mScrollView = new ScrollView(context);
            mTxt.setTextColor(Color.BLACK);
        	mTxt.setTextSize(18);
        	mScrollView.setPadding(10, 0, 10, 60);
        	final LayoutParams params1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            final LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            params2.gravity = Gravity.CENTER;
            mScrollView.addView(mTxt, params2);
            addView(mScrollView, params1);
        }
        void bind(final String txt) {
            mTxt.setText(txt);
        }

    }


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, 0, 0, "Share").setIcon(android.R.drawable.ic_menu_share);
		menu.add(0, 1, 0, "Setting").setIcon(
				getResources().getDrawable(R.drawable.bg_settings));
		return super.onCreateOptionsMenu(menu);
	}


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 0:
			final Uri uri = Uri.parse("smsto://");
//			final String mString = mTextView.getText().toString();
			final Intent it = new Intent(Intent.ACTION_SENDTO, uri);
//			it.putExtra("sms_body", mString);
			startActivity(it);
			break;
		}

		return super.onOptionsItemSelected(item);
	}


}